package cn.ecut.servlet;

import cn.ecut.dao.ContentDao;
import cn.ecut.model.Content;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/likeCount")
public class LikeCountServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String i = request.getParameter("contentid");
        Integer id = Integer.valueOf(i);
        ContentDao contentDao = new ContentDao();
        Content content = contentDao.loadById(id);
        Integer likeCount = content.getLikeCount();
        content.setLikeCount(likeCount+1);

        boolean b = contentDao.updateLikeCount(content);
        if (b){
            response.sendRedirect("/index.jsp");
        }
    }
}
